#include "Complejo.h"

#define RUNTEST(t,d) { cerr << endl << "Corriendo test " << #t << ": " << #d << endl; t(); cerr << "Terminado test " << #t << " OK!" << endl << endl; }


// los comentarios al final de línea con un 1 son errores de precisión: no dan lo mismo que haciendo la cuenta con el octave
// pero si son coherentes entre si tipo a*a con a.cuadrado, etc etc...


void test1(){
	Complex c1(98,-0.3);
	Complex c2(234,69436);

	assert( c1.Re() == 98 && c1.Im() == -0.3 );
	assert( c2.Re() == 234 && c2.Im() == 69436 );
	assert( c1 != c2 );
	
	
	Complex a(3.0,4.0);
	Complex b(a);
	assert(a == b);
	Complex c(0,1);
	assert(c != a);
	assert(c != b);

	c = a;
	assert(c == a);
	assert(!(a != c));
}


void test2(){
	Complex d(0,1);
	Complex a(3.0,4.0);

	assert(a.cuadrado() == Complex(-7,24));
	assert(d.cuadrado() == Complex(-1,0));	
	assert(d.cuadrado() == Complex(1,0));
	
	assert(a == Complex(-7,24));
	assert(a.suma(Complex(10,0)) == Complex(3,24));
	assert(a.suma(Complex(-3,-24)) == Complex(0,0));
	
	/*	octave:9> (3.9+7i) * (34-12i)
		ans =  216.60 + 191.20i		*/

	Complex z = (Complex(3.9,7).producto(Complex(34,-12)));
	Complex res = Complex(216.6,191.2);

//1	assert(res == z);
//1	assert( (Complex(3.9,7).producto(Complex(34,-12))) == Complex(216.6,191.2) );
	
	/*	octave:10> (0.2129+98.0009i) * (187.90-676.99i)
		ans = 6.6386e+04 + 1.8270e+04i			*/
//1	assert( (Complex(0.2129,98.0009).producto(Complex(187.90, -676.99))) == Complex(6.6386e+04,1.8270e+04) );
	
	/*	octave:1> (2+4i)*(3-5i)
		ans =  26 +  2i 	*/
	assert( Complex(2,4).producto(Complex(3,-5)) == Complex(26,2));

	//sumas, restas  locas con el friend operator+
	Complex cc;
	cc = Complex(3,4) + Complex(34,39); // cc debe ser igual a 3+34 + 39+4i = 37+43i
	assert(cc == Complex(37,43));	

	Complex ccc = Complex(0.0001,8) + Complex(-0.0002,98);
	assert( ccc == Complex(-0.0001,106) );
	
	assert( Complex(0,0) == (Complex(0,98) - Complex(0,98)) );
	assert( (Complex(78,-0.009) - Complex(98,-0.008)) != Complex(0,0) );
	

}

void test3(){
	
	Complex c1(67,9);
	Complex c1o = c1;
	Complex c1c = c1.cuadrado();
	Complex c1k = c1o*c1o;
	
	/*	octave:1> power(67+9i,2)
		ans =  4408 + 1206i		*/
	assert( c1k == Complex(4408,1206) );
	assert( c1c == Complex(4408, 1206) );
	assert( c1k == c1c);
	
	c1 = Complex(-9,0.989);
	c1o = c1;
	c1c = c1.cuadrado();
	c1k = c1o*c1o;

	/*	octave:2> power(-9+0.989i,2)
		ans =  80.022 - 17.802i		*/
//1	assert( c1k == Complex(80.022, -17.802) );
//1	assert( c1c == Complex(80.022, -17.802) );
	assert( c1c == c1k ) ;
	


}

void test4(){

	Complex e1(8,23);
	Complex e2(0.123,-0.119);
	Complex e3(987,10928);

	Complex res1(80,230);
	Complex res2(800,2300);
	Complex res3(0.8, 2.3);
	Complex res4(16,46);

	assert( (10 * e1) == res1 );
	assert( (100 * e1) == res2 );
//1	assert( (0.1 * e1) == res3 );
	assert( (2 * e1) == res4 );
	
	//e2
	res1 = Complex(1.23,-1.19);
	res2 = Complex(12.3,-11.9);		
	res3 = Complex(0.0123,-0.0119);
	res4 = Complex(0.246,-0.238);		
	
	assert( (10 * e2) == res1 );
//1	assert( (100 * e2) == res2 );
//	Complex la = 0.1 * e2;
//1	assert( (0.1 * e2) == res3 );
	assert( (2 * e2) == res4 );
	
	//e3
	res1 = Complex(9870,109280);
	res2 = Complex(98700,1092800);		
	res3 = Complex(987,1092.8);
	res4 = Complex(1974,21856);		
	
	assert( (10 * e3) == res1 );
	assert( (100 * e3) == res2 );
//1	assert( (0.1 * e3) == res3 ); //la división por 10 no le gusta un choto
	assert( (2 * e3) == res4 );

	
}
int main(){

	RUNTEST(test1, proyectores y == != y asignacion);
	RUNTEST(test2, sumas restas operators algunas multip);
	RUNTEST(test3, cuadrados);
	RUNTEST(test4, multiplicaciones con escalares - operators asterisco);	


 	cout << "Terminé! :D" <<  endl;	
	return 0;

}
